﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZLCMS.Business.DwzFrame;
using ZLCMS.Data.Model;
using NHibernate;
using DotNet.Common.Command;
using ZLCMS.Commands.Sys.Commands.Product;
//using ZLCMS.Commands.Sys.Commands.Product;

namespace ZLCMS.Web.SystemManage.Basics.Shop.TagInfo
{
    public partial class SetProductTag : System.Web.UI.Page
    {
        protected FrameHelper _framePage;

        protected void Page_Load(object sender, EventArgs e)
        {
            //初始化DWZ控件
            _framePage = new FrameHelper(this);

            //批量删除
            if (Request["ajax"] == "sets")
            {
                String ids = Request["ids"];
                if (!String.IsNullOrEmpty(ids))
                {
                    using (ISession session = DotNet.Common.NHibernateUtil.SessionFactoryHelper.CreateSession())
                    {
                        ICommandResult<SetProductTagResult> cmdrs = new SetProductTagCommand().Execute(new SetProductTagParameter()
                        {
                            ProductNos = ids,
                            Status = Request["status"],
                            TagId = Request["tid"],
                            Type = "multi"
                        });
                        if (cmdrs.Error)
                        {
                            _framePage.Alert(new ReturnCode() { statusCode = 300, message = "操作失败-" + cmdrs.ErrorMsg });
                            return;
                        }
                    }
                }
                _framePage.Alert(new ReturnCode() { statusCode = 200, message = "操作成功!", navTabId = _framePage.NavTabId });
            }
            //单个删除
            else if (!String.IsNullOrEmpty(Request["uid"]))
            {
                using (ISession session = DotNet.Common.NHibernateUtil.SessionFactoryHelper.CreateSession())
                {
                    ICommandResult<SetProductTagResult> cmdrs = new SetProductTagCommand().Execute(new SetProductTagParameter()
                    {
                        ProductNos = Request["uid"],
                        Status = Request["status"],
                        TagId = Request["tid"],
                        Type = "single"
                    });
                    if (cmdrs.Error)
                    {
                        _framePage.Alert(new ReturnCode() { statusCode = 300, message = "操作失败-" + cmdrs.ErrorMsg });
                        return;
                    }
                }
            }
            else
            {
                _framePage.Alert(new ReturnCode() { statusCode = 300, message = "操作失败-参数错误!" });
            }

            _framePage.Alert(new ReturnCode() { statusCode = 200, message = "操作成功!", navTabId = _framePage.NavTabId });
        }
    }
}
      